break statement การใช้
- The break statement is used to end a for loop, while loop, do loop, or switch statement.
- There is also a yield break statement, in which control is unconditionally returned to the caller of the iterator.
- Syntactically, the cases are interpreted as labels, not blocks, and the switch and break statements explicitly change control flow.
- The Break statement may optionally pass any type of expression, which may be accepted by the RECOVER statement to allow further recovery handing.
- When such a loop is created intentionally, there is usually another control structure ( such as a break statement ) that allows termination of the loop.
- Python supports conditional execution of code depending on whether a loop was exited early ( with a break statement ) or not by using an else-clause with the loop.
- The statement has six different formats : it can be used as a return statement, a break statement, a continue statement, an end marker or to leave a procedure.
- In practice, fallthrough is usually prevented with a break keyword at the end of the matching body, which exits execution of the switch block, but this can cause bugs due to unintentional fallthrough if the programmer forgets to insert the break statement.
- Note that the reloop and outloop commands are somewhat analogous to the continue and break statements of languages based on C, except that they must sit at the indenting level of the loop they modify, and they have a condition tag that indicates when the indicated control transfer is to take place.
- This means that a called procedure / function, may issue a BREAK statement, or a Break ( ) expression, to force unfolding of any nested procedure / functions, all the way back to the first outer BEGIN SEQUENCE structure, either after its respective END statement, or a RECOVER clause if present.